<?php

namespace App\Service\Auth\v1_1_8;

use App\Model\User;
use App\Model\UserCancelLog;
use App\Service\BaseService;

/**
 * 注销申请提交
 */
class CancelApplyService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        //1-申请注销，0-撤回注销
        $option = intval($this->request->input('option', 1));
        switch ($option) {
                //撤销注销
            case 0:
                UserCancelLog::cancelApply($userId);
                break;
                //申请注销
            case 1:
                UserCancelLog::addRecord($userId);
                break;
                //直接注销
            case 2:
                //更新状态
                UserCancelLog::where('user_id', $userId)->update(['flag' => UserCancelLog::FLAG_OK]);
                //注销账号
                User::cancelAccount($userId);
                UserCancelLog::addRecord($userId, UserCancelLog::FLAG_OK);
                break;
        }
        $ret['result'] = 1;
        return $ret;
    }
}
